package com.baosight.sczx.common.zm.cInterface.cc;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.util.NumberUtils;
import com.baosight.iplat4j.util.StringUtils;


/**
 * 质量标准化评分
 * <p>Title: ExamineCondition.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-29 上午08:33:42  严洪浩  Create
 *</pre>
 */
public class QualityCondition {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 从表扣分, 更新主表总分
	 * <p>Function: updateExamineCondition</p>
	 * <p>Description: </p>
	 * <p>return value:void</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-30上午01:52:56 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void updateExamineCondition(String fdConditionId) {
		Map<String, String> _argsMap = new HashMap<String, String>();
		_argsMap.put("fdConditionId", fdConditionId);
		
		List _result = new ArrayList();
		_result = dao.query("ZMCCExamineConditionDetail.queryAll", _argsMap);
		
		float _cutPoint = 0;
		for(int i =0; i < _result.size(); i++) {
			HashMap _map = (HashMap)_result.get(i);
			float fdReducePoint = _map.get("fdReducePoint") == null ? 0 : NumberUtils.toFloat(StringUtils.toString(_map.get("fdReducePoint")));//扣分
			float fdPointValue = _map.get("fdPointValue") == null ? 0 : NumberUtils.toFloat(StringUtils.toString(_map.get("fdPointValue")));//计分率
			
			_cutPoint += fdReducePoint * fdPointValue;
		}
		
		float value = Qualitystandard.getSumPoint() - _cutPoint;
		if(value < 0) {
			value = 0;
		}
		
		//四舍五入  保留一位小数
		BigDecimal temp = new BigDecimal(value);
		float _value = temp.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
		
		Map _args = new HashMap();
		_args.put("fdKeyId", fdConditionId);
		_args.put("fdTrainingStarttime", _value);
		dao.update("ZMCCExamineCondition.updateStarttime", _args);
	}
}
